package com.projectmanagement.model.dao.hibernate;

import org.hibernate.Session;

import com.projectmanagement.helpers.hibernate.HibernateUtil;
import com.projectmanagement.model.dao.CompanyDAO;
import com.projectmanagement.model.dao.DAOFactory;
import com.projectmanagement.model.dao.FileDAO;
import com.projectmanagement.model.dao.GroupDAO;
import com.projectmanagement.model.dao.MessageDAO;
import com.projectmanagement.model.dao.PermissionDAO;
import com.projectmanagement.model.dao.PriorityLevelDAO;
import com.projectmanagement.model.dao.ProjectCommentDAO;
import com.projectmanagement.model.dao.ProjectDAO;
import com.projectmanagement.model.dao.ProjectFileDAO;
import com.projectmanagement.model.dao.ProjectMessageDAO;
import com.projectmanagement.model.dao.ProjectMilestoneDAO;
import com.projectmanagement.model.dao.ProjectPermissionDAO;
import com.projectmanagement.model.dao.ProjectTaskDAO;
import com.projectmanagement.model.dao.ProjectTaskListDAO;
import com.projectmanagement.model.dao.ProjectUserDAO;
import com.projectmanagement.model.dao.ReceivedMessageDAO;
import com.projectmanagement.model.dao.RoleDAO;
import com.projectmanagement.model.dao.SentMessageDAO;
import com.projectmanagement.model.dao.UserDAO;

public class HibernateDAOFactory extends DAOFactory {

	private GenericHibernateDAO<?,?> instantiateDAO(Class<?> daoClass) {
		try {
			GenericHibernateDAO<?,?> dao = (GenericHibernateDAO<?,?>) daoClass
					.newInstance();
			return dao;
		} catch (Exception ex) {
			throw new RuntimeException("Can not instantiate DAO: " + daoClass,
					ex);
		}
	}

	protected Session getCurrentSession() {
		return HibernateUtil.getInstance().getSessionFactory().getCurrentSession();
	}

	@Override
	public UserDAO getUserDAO() {
		return (UserDAO)instantiateDAO(UserDAOImpl.class);
	}

	@Override
	public CompanyDAO getCompanyDAO() {
		return (CompanyDAO)instantiateDAO(CompanyDAOImpl.class);
	}

	@Override
	public FileDAO getFileDAO() {
		return (FileDAO)instantiateDAO(FileDAOImpl.class);
	}

	@Override
	public GroupDAO getGroupDAO() {
		return (GroupDAO)instantiateDAO(GroupDAOImpl.class);
	}

	@Override
	public MessageDAO getMessageDAO() {
		return (MessageDAO)instantiateDAO(MessageDAOImpl.class);
	}

	@Override
	public PermissionDAO getPermissionDAO() {
		return (PermissionDAO)instantiateDAO(PermissionDAOImpl.class);
	}

	@Override
	public PriorityLevelDAO getPriorityLevelDAO() {
		return (PriorityLevelDAO)instantiateDAO(PriorityLevelDAOImpl.class);
	}

	@Override
	public ProjectCommentDAO getProjectCommentDAO() {
		return (ProjectCommentDAO)instantiateDAO(ProjectCommentDAOImpl.class);
	}

	@Override
	public ProjectDAO getProjectDAO() {
		return (ProjectDAO)instantiateDAO(ProjectDAOImpl.class);
	}

	@Override
	public ProjectFileDAO getProjectFileDAO() {
		return (ProjectFileDAO)instantiateDAO(ProjectFileDAOImpl.class);
	}

	@Override
	public ProjectMessageDAO getProjectMessageDAO() {
		return (ProjectMessageDAO)instantiateDAO(ProjectMessageDAOImpl.class);
	}

	@Override
	public ProjectMilestoneDAO getProjectMilestoneDAO() {
		return (ProjectMilestoneDAO)instantiateDAO(ProjectMilestoneDAOImpl.class);
	}

	@Override
	public ProjectPermissionDAO getProjectPermissionDAO() {
		return (ProjectPermissionDAO)instantiateDAO(ProjectPermissionDAOImpl.class);
	}

	@Override
	public ProjectTaskDAO getProjectTaskDAO() {
		return (ProjectTaskDAO)instantiateDAO(ProjectTaskDAOImpl.class);
	}

	@Override
	public ProjectTaskListDAO getProjectTaskListDAO() {
		return (ProjectTaskListDAO)instantiateDAO(ProjectTaskListDAOImpl.class);
	}

	@Override
	public ProjectUserDAO getProjectUserDAO() {
		return (ProjectUserDAO)instantiateDAO(ProjectUserDAOImpl.class);
	}

	@Override
	public ReceivedMessageDAO getReceivedMessageDAO() {
		return (ReceivedMessageDAO)instantiateDAO(ReceivedMessageDAOImpl.class);
	}

	@Override
	public RoleDAO getRoleDAO() {
		return (RoleDAO)instantiateDAO(RoleDAOImpl.class);
	}

	@Override
	public SentMessageDAO getSentMessageDAO() {
		return (SentMessageDAO)instantiateDAO(SentMessageDAOImpl.class);
	}

}
